﻿package com.sgcc.nfc.lock.data.repository

import com.sgcc.nfc.lock.core.network.NetworkResult
import com.sgcc.nfc.lock.core.network.safeApiCallVoid
import com.sgcc.nfc.lock.data.remote.api.LockApi
import com.sgcc.nfc.lock.data.remote.api.NfcLockRequest
import com.sgcc.nfc.lock.domain.repository.NfcRepository
import com.sgcc.nfc.lock.domain.model.NfcOperationParams
import javax.inject.Inject

class NfcRepositoryImpl @Inject constructor(
    private val lockApi: LockApi
) : NfcRepository {

    override suspend fun openLock(params: NfcOperationParams): NetworkResult<Unit> {
        return safeApiCallVoid {
            lockApi.openLock(
                NfcLockRequest(
                    lockNfcId = params.lockNfcId,
                    roomId = params.roomId,
                    longitude = params.longitude,
                    latitude = params.latitude,
                    remark = params.remark
                )
            )
        }
    }

    override suspend fun closeLock(params: NfcOperationParams): NetworkResult<Unit> {
        return safeApiCallVoid {
            lockApi.closeLock(
                NfcLockRequest(
                    lockNfcId = params.lockNfcId,
                    roomId = params.roomId,
                    longitude = params.longitude,
                    latitude = params.latitude,
                    remark = params.remark
                )
            )
        }
    }
}
